package lsysteem;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class LSView extends JFrame implements IView
{
	private IModelData _modelData;
	private LSPanel _panel = new LSPanel();
	
	protected LSTurtle _turtle;
	
	public LSView(){
		this.add(_panel);
		this.setSize(1000,800);
		this.setVisible(true);
	}
	
	public void updateView(IModelData m)
	{
		_modelData = m;
		
		_turtle = new LSTurtle(m,this,0);
		_turtle.start();
	}
	
	
	protected class LSPanel extends JPanel
	{
		public LSPanel()
		{
			this.setSize(1000,800);
		}
		
		@Override
		public void paint(Graphics g)
		{
			g.setColor(Color.WHITE);
			g.fillRect(0, 0, 1000, 800);
			g.setColor(Color.black);
			System.out.println("View: lines to draw: "+_turtle.closedList.size());
			
			for(LSLine l:_turtle.closedList)
			{
				if(l.previous != null){
					//System.out.println("test "+l.previous.x+" "+l.previous.y+" "+l.x+" "+l.y+" ");
					g.drawLine(l.previous.x, l.previous.y, l.x, l.y);
				}
			}
		}
	}

}
